define(function (require, exports, module) {
	var store = require("store");
	var activeUser = store.get("user");
	var Dialog=require("dialog");
	var aw = require("ajaxwrapper");
	var Form = require("form");
	
    module.exports = {
    		// 补办
        	gridBb : function(data, widget){
    			var remarkForm4 =new Form({
    				parentNode : ".J-form-dialog",
    				autoRender : false,
            		model:{
    					id:"remarkForm4",
    					defaultButton:false,
    					items:[{
    						name : "cardNo",
    						label : "原卡号",
    						defaultValue : data.roomPersonalInfo.consumeCard.cardNumber,
    						readonly : true,
    					},{
    						name : "newcardNo",
    						label : "新卡号",
    						validate : ["required"],
    						exValidate: function(value) {
    							var reg = /[\u4e00-\u9fa5]/;
                                if (reg.test(value) || data.roomPersonalInfo.consumeCard.cardNumber==value) {
                                    return "卡号格式不正确或者与原卡号相同！";
                                } else {
                                    return true;
                                }
                            }, 
    					},{
    						name  : "roomPersonalInfo.personalInfo.name",
    						label : "姓名",
    						defaultValue : data.roomPersonalInfo.personalInfo.name,
    						readonly : true,
    					},{
    						name  : "balance",
    						label : "余额(元)",
    						defaultValue : data.balance,
    						readonly : true,
    					},{
    						name  : "operator",
    						label : "经办人",
    						defaultValue : activeUser.name,
    						readonly : true,
    					},{
    						name  : "operateDate",
    						label : "办理日期",
    						defaultValue : moment(new Date()).format("YYYY-MM-DD"),
    						type : "date",
    						readonly : true,
    					}]
    				 }
    			});
    			widget.set("remarkForm4",remarkForm4);
    			Dialog.showComponent(remarkForm4,{
    				defaultButton:false,
    				title: "补办",
    				buttons :[{
    					id:"save",
    					text:"确定",
						className:"btn-save",
    					handler:function(){
    						if(remarkForm4.valid()){
    							var FormData = remarkForm4.getData();
    							var saveData = FormData;
    							saveData.travelAccount = {
    									pkTravelAccount : data.pkTravelAccount,	
    									roomPersonalInfo : {
    										consumeCard : {
    											cardNumber : FormData.newcardNo
    										}
    									}
    							}
    							saveData.description = moment(FormData.operateDate).format("YYYY年MM月DD日")+"补办";
    							saveData.consumeType = "Reissue";
    							saveData.operator = activeUser.pkUser;
    							saveData.servicePoint = widget.get("subnav") .getValue("servicePoint");
    							aw.saveOrUpdate("api/cate/consumecard/reissue",aw.customParam(saveData),function(saveData){
    								Dialog.close();
    			          			widget.get("grid").refresh();
    			       			});
    						};
    					}
    				},{
    					id:"close",
    					text:"取消",
    					handler:function(){
    						Dialog.close();
    					}
    				}]
    			});
    	},

    	// 挂失
    	gridGs : function(data, widget){
			var remarkForm2 =new Form({
				parentNode:".J-form-dialog",
				autoRender : false,
        		model:{
					id:"remarkForm2",
					defaultButton:false,
					items:[{
						name : "cardNo",
						label : "卡号",
						defaultValue : data.roomPersonalInfo.consumeCard.cardNumber,
						readonly : true,
					},{
						name  : "roomPersonalInfo.personalInfo.name",
						label : "姓名",
						defaultValue : data.roomPersonalInfo.personalInfo.name,
						readonly : true,
					},{
						name  : "balance",
						label : "余额(元)",
						defaultValue : data.balance,
						readonly : true,
					},{
						name  : "operator",
						label : "经办人",
						defaultValue : activeUser.name,
						readonly : true,
					},{
						name  : "operateDate",
						label : "办理日期",
						type  : "date",
						defaultValue : moment(new Date()).format("YYYY-MM-DD"),
						readonly : true,
					},{
						name  : "description",
						"break" : true,
						label : "备注"
					}]
				 }
			});
			widget.set("remarkForm2",remarkForm2);
			Dialog.showComponent(remarkForm2,{
				defaultButton:false,
				title: "挂失",
				buttons :[{
					id:"save",
					text:"确定",
					className:"btn-save",
					handler:function(){
						if(remarkForm2.valid()){
							var FormData = remarkForm2.getData();
							FormData.operator = activeUser.pkUser;
							FormData.consumeType = "Lose";
							FormData.travelAccount = data.pkTravelAccount;
							FormData.servicePoint = widget.get("subnav") .getValue("servicePoint");
							aw.saveOrUpdate("api/cate/consumecard/loss",aw.customParam(FormData),function(FormData){
								Dialog.close();
			          			widget.get("grid").refresh();
			       			});
						};
					}
				},{
					id:"close",
					text:"取消",
					handler:function(){
						Dialog.close();
					}
				}]
			});
    	},

    	gridMx : function(data, widget){
    		widget.set("pkTravelAccount", data.pkTravelAccount);
    		widget.show(".J-detailgrid").hide(".J-grid");
    		widget.get("subnav").hide(["search","status","grantDate","add"]).show(["return","operateDate"]);
    		widget.get("detailGrid").refresh();
    	},

        gridRecharge : function(data, widget){
			var remarkForm =new Form({
				autoRender : false,
        		model:{
					id:"remarkForm",
					defaultButton:false,
					items:[{
						name : "cardNo",
						label : "卡号",
						defaultValue : data.roomPersonalInfo.consumeCard.cardNumber,
						readonly : true,
					},{
						name : "name",
						label : "姓名",
						defaultValue : data.roomPersonalInfo.personalInfo.name,
						readonly : true,
					},{
						name  : "money",
						label : "充值金额(元)",
						validate : ["required"],
						exValidate: function(value) {
							var reg = /[^\- \d.]/g;
                            if (reg.test(value)) {
                                return "金额必须输入数字且不能为负！";
                            } else {
                                return true;
                            }
                        },
					},{
						name  : "operator",
						label : "经办人",
						defaultValue : activeUser.name,
						readonly : true,
					},{
						name  : "operateDate",
						label : "办理日期",
						type  : "date",
						defaultValue : moment(new Date()).format("YYYY-MM-DD"),
						readonly : true,
					}]
				 }
			});
			widget.set("remarkForm",remarkForm);
			Dialog.showComponent(remarkForm,{
				defaultButton:false,
				title: "充值",
				buttons :[{
					id:"save",
					text:"确认",
					className:"btn-save",
					handler:function(){
						if(remarkForm.valid()){
							var FormData = remarkForm.getData();
							FormData.servicePoint = widget.get("subnav") .getValue("servicePoint");
							FormData.operator = activeUser.pkUser;
							FormData.travelAccount = data.pkTravelAccount;
							FormData.consumeType = "Recharge";
							aw.saveOrUpdate("api/cate/consumecard/recharge",aw.customParam(FormData),function(saveData){
								Dialog.close();
			          			widget.get("grid").refresh();
			       			});
						};
					}
				},{
					id:"close",
					text:"取消",
					handler:function(){
						Dialog.close();
					}
				}]
			});
        },

    	gridTk : function(data, widget){
			var remarkForm3 =new Form({
				parentNode:".J-form-dialog",
				autoRender : false,
        		model:{
					id:"remarkForm3",
					defaultButton:false,
					items:[{
						name : "cardNo",
						label : "卡号",
						defaultValue : data.roomPersonalInfo.consumeCard.cardNumber,
						readonly : true,
					},{
						name  : "travelContract.member.personalInfo.name",
						label : "姓名",
						defaultValue : data.roomPersonalInfo.personalInfo.name,
						readonly : true,
					},{
						name  : "balance",
						label : "应退余额(元)",
						defaultValue : data.balance,
						readonly : true,
					},{
						name  : "money",
						label : "实退余额(元)",
						defaultValue : data.balance,
						validate : ["required"],
						exValidate: function(value) {
		                	var reg = /^([1-9][\d]{0,7}|0)(\.[\d]{1,2})?$/;
                            if (!reg.test(value) || data.balance<value) {
                                return "金额格式不正确或者大于余额！";
                            } else {
                                return true;
                            }
                        }, 
					},{
						name  : "operator",
						label : "经办人",
						defaultValue : activeUser.name,
						readonly : true,
					},{
						name  : "operateDate",
						label : "办理日期",
						defaultValue : moment(new Date()).format("YYYY-MM-DD"),
						type : "date",
						readonly : true,
					},{
						name  : "description",
						label : "备注"
					}]
				 }
			});
			widget.set("remarkForm3",remarkForm3);
			Dialog.showComponent(remarkForm3,{
				defaultButton:false,
				title: "退卡",
				buttons :[{
					id:"save",
					text:"确定",
					className:"btn-save",
					handler:function(){
						if(remarkForm3.valid()){
							var FormData = remarkForm3.getData();
							var saveData = FormData;
							saveData.operator = activeUser.pkUser;
							saveData.travelAccount = data.pkTravelAccount;
							saveData.consumeType = "Returned";
							saveData.servicePoint = widget.get("subnav") .getValue("servicePoint"); 
							aw.saveOrUpdate("api/cate/consumecard/returned",aw.customParam(saveData),function(saveData){
								Dialog.close();
			          			widget.get("grid").refresh();
			       			});
						};
					}
				},{
					id:"close",
					text:"取消",
					handler:function(){
						Dialog.close();
					}
				}]
			});
    	},
      };
});
